home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / library / help / tcl / intro / keyedlists next >
Encoding:
Text File  |  1993-10-26  |  1.8 KB  |  45 lines  |  [TEXT/$Tcl]

  1.  
  2.  
  3.      KEYED LISTS
  4.           Extended Tcl defines a special type of list referred  to  as
  5.           keyed  lists.   These  lists provided a structured data type
  6.           built upon standard Tcl lists.  This provides a  functional-
  7.           ity similar to structs in the C programming language.
  8.  
  9.           A keyed list is a list in which each element contains a  key
  10.           and  value  pair.   These  element pairs are stored as lists
  11.           themselves, where the key is the first element of the  list,
  12.           and  the  value  is  the  second.   The  key-value pairs are
  13.           refered to as fields.  This is an example of a keyed list:
  14.  
  15.                    {{NAME  {Frank  Zappa}}  {JOB  {musician  and  com-
  16.                poser}}}
  17.  
  18.           If the variable person contained the above list, then  keyl-
  19.           get  person  NAME would return {Frank Zappa}.  Executing the
  20.           command:
  21.  
  22.                keylset person ID 106
  23.  
  24.           would make person contain
  25.  
  26.                    {{ID 106} {NAME {Frank Zappa}} {JOB  {musician  and
  27.                composer}}
  28.  
  29.           Fields may contain subfields; `.' is the  seperator  charac-
  30.           ter.   Subfields  are  actually  fields  where  the value is
  31.           another keyed list.  Thus the following  list  has  the  top
  32.           level  fields  ID  and  NAME,  and  subfields NAME.FIRST and
  33.           NAME.LAST:
  34.  
  35.                    {ID 106} {NAME {{FIRST Frank} {LAST Zappa}}}
  36.  
  37.           There is no limit  to  the  recursive  depth  of  subfields,
  38.           allowing one to build complex data structures.
  39.  
  40.           Keyed lists are constructed and accessed  via  a  number  of
  41.           commands.   All keyed list management commands take the name
  42.           of the variable containing the keyed  list  as  an  argument
  43.           (i.e.  passed  by  reference),  rather than passing the list
  44.           directly.
  45.